package com.qingzhuge.member.controller;

import com.qingzhuge.controller.base.AbstractController;
import com.qingzhuge.dto.response.ResponseBodyDto;
import com.qingzhuge.member.dto.request.SysHelpRequestDto;
import com.qingzhuge.member.dto.response.SysHelpResponseDto;
import com.qingzhuge.member.entity.SysHelp;
import com.qingzhuge.member.service.ISysHelpService;
import com.qingzhuge.utils.PageUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import static com.qingzhuge.common.Constants.Controller.PATH_BY_ID;
import static com.qingzhuge.common.Constants.Controller.PATH_PAGE;

/**
 * @author : zero.xiao
 * @description :
 * @date : 2018/9/25 0025 下午 17:36
 * @modified :
 * @since :
 */
@RestController
@RequestMapping("/api/open/help")
@Api(tags = "A用户帮助")
public class ApiSysHelpController extends AbstractController {
    @Resource
    private ISysHelpService helpService;

    @ApiOperation(value = "前端分页")
    @PutMapping(PATH_PAGE)
    public ResponseEntity<ResponseBodyDto<PageUtil<SysHelpResponseDto>>> query(@RequestBody(required = false) SysHelpRequestDto requestDto) {

        PageUtil<SysHelp> page = helpService.query(doDto2Bean(requestDto, SysHelp.class));
        return returnSuccess(page, SysHelpResponseDto.class);
    }

    @ApiOperation(value = "详情")
    @GetMapping(PATH_BY_ID)
    public ResponseEntity<ResponseBodyDto<SysHelpResponseDto>> get(@PathVariable Long id) {
        SysHelp help = helpService.findById(id);
        return returnSuccess(doBean2Dto(help, SysHelpResponseDto.class));
    }
}
